﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ChatPanel : BasePanel
{
	public Text contentText;
	public InputField inputField;
	public Queue<string> queues => GetComponent<ChatRequest>().queues;


	CanvasGroup canvasGroup;
	private void Awake() {
		canvasGroup = GetComponent<CanvasGroup>();
		uipanelType = UIPanelType.ChatPanel;
	}

	public override void OnEnter() {
		Debug.Log("port");
		canvasGroup.blocksRaycasts = true;
		canvasGroup.alpha = 1;
		transform.SetAsLastSibling();
		GetComponent<RectTransform>().localScale = Vector3.one;
	}

	public override void OnExit() {
		canvasGroup.blocksRaycasts = false;
		canvasGroup.alpha = 0;
		GetComponent<RectTransform>().localScale = Vector3.zero;
	}

	public override void OnPause() {
		canvasGroup.blocksRaycasts = false;
	}

	public override void OnResume() {
		canvasGroup.blocksRaycasts = true;
	}



	public void OnClickEnter() {
		string data = inputField.text;
		inputField.text = "";
		if (string.IsNullOrEmpty(data)) return;
		GetComponent<ChatRequest>().RequestChat(data);
		uiMng.PopStack();
	}

	public void OnClickClose() {
		uiMng.PopStack();
	}


	public void ShowChat(string s) {
		contentText.text += s + "\n";
	}

}
